package com.bida.controller.user;


import com.bida.domain.dto.OrdersPaymentDTO;
import com.bida.domain.dto.OrdersSubmitDTO;
import com.bida.domain.po.Orders;
import com.bida.domain.vo.OrderPaymentVO;
import com.bida.domain.vo.OrderSubmitVO;
import com.bida.domain.vo.OrderVO;
import com.bida.result.PageResult;
import com.bida.result.Result;
import com.bida.service.IOrdersService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-09-08
 */
@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrdersController {

    @Resource
    private IOrdersService orderService;


    /**
     * 用户下单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> userSubmitOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = orderService.userSubmitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> paymentOrder(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.paymentOrder(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * 历史订单查询
     * @param page
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(int page, int pageSize, Integer status){
        PageResult pageResult = orderService.getHistoryOrders(page,pageSize,status);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OrderVO> getOrdersInfoById(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.getOrdersInfoById(id);
        return Result.success(orderVO);
    }

    /**
     * 取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    public Result cancelOrderById(@PathVariable("id") Long id) throws Exception {
        orderService.cancelOrderById(id);
        return Result.success();
    }

    /**
     * 再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    public Result repetitionOrderAgain(@PathVariable("id") Long id) throws Exception{
         orderService.repetitionOrderAgain(id);
        return Result.success();
    }

    /**
     * 催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    public Result userReminder(@PathVariable("id") Long id){
        orderService.userReminder(id);
        return Result.success();
    }





}
